package ar.edu.itba.it.paw.domain;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

@Entity
public class Question extends PersistentAttributes{

	//Usuario al que se le pregunta
	@ManyToOne
	private User user;
	private String question;
	private String answer;
	private Date date;
	@ManyToOne
	private Product product;

	protected Question(){

	}
	
	public Question(Product product,User user, String question, String answer, Date date){
		this.answer = answer;
		setDate(date);
		setQuestion(question);
		setUser(user);
		setProduct(product);
	}
	
	public User getUser() {
		return user;
	}
	
	private void setUser(User user) {
		if(user == null){
			throw new IllegalArgumentException();
		}
		this.user = user;
	}
	
	public String getQuestion() {
		return question;
	}
	
	private void setQuestion(String question) {
		if(question == null){
			throw new IllegalArgumentException();
		}
		this.question = question;
	}
	
	public String getAnswer() {
		return answer;
	}
	
	public void setAnswer(String answer) {
		if(answer == null){
			throw new IllegalArgumentException();
		}
		this.answer = answer;
	}
	
	public Date getDate() {
		return date;
	}
	
	private void setDate(Date date) {
		if(date == null){
			throw new IllegalArgumentException();
		}
		this.date = date;
	}

	public Product getProduct() {
		return product;
	}
	
	private void setProduct(Product product) {
		if(product == null){
			throw new IllegalArgumentException();
		}
		this.product = product;
	}
	
	@Override
	public String toString() {
		return "Question [user=" + user + ", question=" + question
				+ ", answer=" + answer + ", date=" + date + ", product="
				+ product + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((product == null) ? 0 : product.hashCode());
		result = prime * result
				+ ((question == null) ? 0 : question.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Question other = (Question) obj;
		if (product == null) {
			if (other.product != null)
				return false;
		} else if (!product.equals(other.product))
			return false;
		if (question == null) {
			if (other.question != null)
				return false;
		} else if (!question.equals(other.question))
			return false;
		return true;
	}
}
